package com.ksyun.campus.dataserver.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class NetworkUtils {

    /**
     * 获取本机的实际IP地址，而不是127.0.0.1
     *
     * @return 实际的IP地址
     */
    public static String getLocalIp() {
        try {
            InetAddress inetAddress = InetAddress.getLocalHost();
            return inetAddress.getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return "127.0.0.1"; // 在获取实际IP失败的情况下返回127.0.0.1
        }
    }
}
